package com.forehope.portal.controller;

import com.actionsoft.apps.resource.AppContext;
import com.actionsoft.bpms.bo.design.model.BOItemModel;
import com.actionsoft.bpms.bo.design.model.BOModel;
import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.model.def.ProcessDefinition;
import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.commons.formfile.model.delegate.FormFile;
import com.actionsoft.bpms.commons.htmlframework.AlertWindow;
import com.actionsoft.bpms.commons.htmlframework.HtmlPageTemplate;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.commons.portal.pub.web.PublicPortalWeb;
import com.actionsoft.bpms.commons.security.ac.model.AccessControlModel;
import com.actionsoft.bpms.commons.security.basic.PermAPIManager;
import com.actionsoft.bpms.commons.security.basic.Query1Model;
import com.actionsoft.bpms.commons.security.basic.model.PermissionAssnModel;
import com.actionsoft.bpms.org.cache.UserMapCache;
import com.actionsoft.bpms.org.model.UserMapModel;
import com.actionsoft.bpms.org.model.UserModel;
import com.actionsoft.bpms.server.RequestParams;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.server.bind.annotation.Controller;
import com.actionsoft.bpms.server.bind.annotation.Mapping;
import com.actionsoft.bpms.server.fs.DCContext;
import com.actionsoft.bpms.server.fs.dc.DCConst;
import com.actionsoft.bpms.server.fs.dc.DCProfileManager;
import com.actionsoft.bpms.server.fs.impl.PhotoProcessor;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.bpms.util.UtilString;
import com.actionsoft.sdk.local.SDK;
import com.actionsoft.sdk.local.api.AppAPI;
import com.actionsoft.sdk.local.api.PermAPI;
import com.actionsoft.sdk.local.api.PortalAPI;
import com.actionsoft.sdk.local.api.TaskQueryAPI;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.forehope.portal.aslpUtil.CMSUtil;
import com.forehope.portal.aslpUtil.MeetingUtil;
import com.forehope.portal.aslpUtil.ProcessUtil;
import jodd.util.StringUtil;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

import static com.forehope.portal.aslpUtil.MailUtil.sendMailToUser;

@Controller
public class PortalPersonController {
    /**
     * 待办消息查询
     */
    @Mapping("portal.person.todoList")
    public ResponseObject getTodoList(UserContext userContext, RequestParams requestParams) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            JSONObject returnData = new JSONObject();

            ProcessUtil processUtil = new ProcessUtil();
            List<JSONObject> result = processUtil.getTodoList(userContext);

            Map<String, Object> resultMap = processUtil.dueData(userContext,requestParams, result, "todo");

            int totalNum = (int) resultMap.get("totalNum");
            List<JSONObject> pageList = (List<JSONObject>) resultMap.get("resultData");
            returnData.put("totalNum", totalNum);
            returnData.put("list", pageList);
            responseObject.setData(returnData);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 已办消息查询
     */
    @Mapping("portal.person.tractList")
    public ResponseObject getTrackList(UserContext userContext, RequestParams requestParams) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            JSONObject returnData = new JSONObject();

            ProcessUtil processUtil = new ProcessUtil();
            List<JSONObject> result = processUtil.getTrackList(userContext, requestParams);
            /**
             * 获取数量
             */
            int totalNum = processUtil.getTaskNum(userContext);
            returnData.put("totalNum", totalNum);
            returnData.put("list", result);
            responseObject.setData(returnData);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 我的发起查询
     */
    @Mapping("portal.person.mycreate")
    public ResponseObject getMyCreateList(UserContext userContext, RequestParams requestParams) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            JSONObject returnData = new JSONObject();

            ProcessUtil processUtil = new ProcessUtil();
            List<JSONObject> result = processUtil.getMyCreateList(userContext);

            Map<String, Object> resultMap = processUtil.dueData(userContext,requestParams, result, "mycreate");

            int totalNum = (int) resultMap.get("totalNum");
            List<JSONObject> pageList = (List<JSONObject>) resultMap.get("resultData");
            returnData.put("totalNum", totalNum);
            returnData.put("list", pageList);
            responseObject.setData(returnData);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }


    /**
     * 任务数量查询
     */
    @Mapping("portal.person.gettasknum")
    public ResponseObject getTaskNum(UserContext userContext) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            JSONObject returnData = new JSONObject();
            ProcessUtil processUtil = new ProcessUtil();
            ResponseObject result = processUtil.getTodoNum(userContext);

//            List<JSONObject> resultfq = processUtil.getMyCreateList(userContext);

            /**
             * 查询待办数量
             */
            if (result.isOk()) {
                Map map = result.getData(Map.class);
                returnData.put("todo", map.get("count"));
            } else {
                responseObject = ResponseObject.newErrResponse("查询出错！");
                return responseObject;
            }
            /**
             * 查询逾期数量
             */
            long countYQ = SDK.getTaskQueryAPI().target(userContext.getUID()).delayTask().activeTask().count();
//            List<JSONObject> yq = result.stream().filter(jsonObject -> jsonObject.getBoolean("isYq") == true).collect(Collectors.toList());
            returnData.put("yq", countYQ);
            /**
             * 查询发起数量
             */
//            returnData.put("mycreate", resultfq.size());

            String sqlCount = "select count(ID) as count from wfc_process where CREATEUSER = '" + userContext.getUID() + "'  and STARTACTIVITYID IS NOT NULL";
            String cont = DBSql.getString(sqlCount);
            returnData.put("mycreate", cont);
            responseObject.setData(returnData);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 顶部菜单
     */
    @Mapping("portal.person.gettopurl")
    public ResponseObject getTopUrl(UserContext userContext) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            List<BO> list = SDK.getBOAPI().query("BO_EU_PERSON_DBCD").orderBy("ORDERNUM").asc().list();
            List<JSONObject> resultList = new ArrayList<>();
            for (BO bo1 : list) {
                boolean result = SDK.getPermAPI().havingACPermission(userContext.getUID(), "platform.process", bo1.getId(), 0);
                if (result) {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("name", bo1.getString("NAME"));
                    jsonObject.put("logo", bo1.getString("LOGO"));
                    if (bo1.getString("OPENURL").contains("./")) {
                        jsonObject.put("openUrl", SDK.getPortalAPI().getPortalUrl() + "/r/" + (SDK.getRuleAPI().executeAtScript(bo1.getString("OPENURL"), userContext).replace("./", "")));
                    } else {
                        jsonObject.put("openUrl", (SDK.getRuleAPI().executeAtScript(bo1.getString("OPENURL"), userContext).replace("./", "")));
                    }
                    resultList.add(jsonObject);
                }
            }
            responseObject.setData(resultList);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 应用入口
     */
    @Mapping("portal.person.getsystem")
    public ResponseObject getSystem(UserContext userContext) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            List<BO> list = SDK.getBOAPI().query("BO_ACT_SSO_SYSTEM").addQuery("ISACTIVE=", 1).list();
            List<JSONObject> resultList = new ArrayList<>();
            for (BO bo1 : list) {
                boolean result = SDK.getPermAPI().havingACPermission(userContext.getUID(), "platform.process", bo1.getId(), 0);
                if (result) {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("name", bo1.getString("SSONAME"));

                    List<FormFile> queryPicter = SDK.getBOAPI().getFiles(bo1.getId(), "ICON32");
                    if (queryPicter != null && queryPicter.size() > 0) {
                        FormFile file = queryPicter.get(0);
                        DCContext fileDc = new DCContext(userContext, DCProfileManager.getDCProfile("com.actionsoft.apps.addons.sso", DCConst.REPOSITORY_UI_FILE), "com.actionsoft.apps.addons.sso", file.getId(), file.getBoItemName(), file.getFileName());
                        String downloadURL = SDK.getPortalAPI().getPortalUrl() + "/r/" + fileDc.getDownloadURL().replace("./", "").replace("sid=", "sid=" + userContext.getSessionId());

                        jsonObject.put("logo32", downloadURL);

                    }
                    List<FormFile> queryPicter1 = SDK.getBOAPI().getFiles(bo1.getId(), "ICON96");
                    if (queryPicter1 != null && queryPicter1.size() > 0) {
                        FormFile file1 = queryPicter1.get(0);
                        DCContext fileDc1 = new DCContext(userContext, DCProfileManager.getDCProfile("com.actionsoft.apps.addons.sso", DCConst.REPOSITORY_UI_FILE), "com.actionsoft.apps.addons.sso", file1.getId(), file1.getBoItemName(), file1.getFileName());
                        String downloadUR1L = SDK.getPortalAPI().getPortalUrl() + "/r/" + fileDc1.getDownloadURL().replace("./", "").replace("sid=", "sid=" + userContext.getSessionId());

                        jsonObject.put("logo96", downloadUR1L);
                    }
                    jsonObject.put("loginUrl", SDK.getPortalAPI().getPortalUrl() + "/r/w?sid=" + userContext.getSessionId() + "&cmd=com.actionsoft.apps.addons.sso_access&ssoId=" + bo1.getId());
                    jsonObject.put("order", bo1.getString("ORDERINDEX"));
                    resultList.add(jsonObject);
                }
            }
            responseObject.setData(resultList);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 帮助文档
     */
    @Mapping("portal.person.helpword")
    public ResponseObject getHelpWord(UserContext userContext) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            List<BO> list = SDK.getBOAPI().query("BO_EU_PERSON_HELPWORD").list();
            List<JSONObject> resultList = new ArrayList<>();
            for (BO bo1 : list) {
                boolean result = SDK.getPermAPI().havingACPermission(userContext.getUID(), "platform.process", bo1.getId(), 0);
                if (result) {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("name", bo1.getString("TITLE"));
                    jsonObject.put("remark", bo1.getString("REMARK"));
                    jsonObject.put("bindid", bo1.getBindId());
                    resultList.add(jsonObject);
                }
            }
            responseObject.setData(resultList);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 打开、预览帮助文档
     */
    @Mapping("portal.person.openhelpword")
    public String openHelp(UserContext userContext, String bindid) {
        BO bo1 = SDK.getBOAPI().query("BO_EU_PERSON_HELPWORD", true).bindId(bindid).detail();
        String info = bo1.getString("INFO");

        String title = bo1.getString("TITLE");
        Map<String, Object> macroLibraries = new LinkedHashMap<String, Object>();
        macroLibraries.put("title", title);
        String pattern = "(?<=&sid=)[^&]+";
        info = info.replaceAll(pattern, userContext.getSessionId());
        macroLibraries.put("info", info);
        return HtmlPageTemplate.merge("com.awspaas.user.apps.forehope.portal", "help.html", macroLibraries);
    }

    /**
     * 通用功能查询
     */
    @Mapping("portal.person.getfunctionlist")
    public ResponseObject getFunctionList(UserContext userContext) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            List<JSONObject> list = new ArrayList<>();
            UserModel currentUserModel = SDK.getORGAPI().getUser(userContext.getUID());
            Query1Model q1Model = new Query1Model();
            List<PermissionAssnModel> userPermissionAssnList = q1Model.getUserPermissionAssnListByUID(userContext.getUID());
            List<PermissionAssnModel> deptPermissionAssnList = q1Model.getDeptPermissionAssnListByDeptId(currentUserModel.getDepartmentId());
            List<PermissionAssnModel> rolePermissionAssnList = q1Model.getRolePermissionAssnListByRoleId(currentUserModel.getRoleId());
            List<UserMapModel> mapRoles = UserMapCache.getMapListOfUser(userContext.getUID());

            /**
             * 查询个人是否有通用功能列表了
             */
            BO bo = SDK.getBOAPI().query("BO_EU_PERSON_MY_DH").addQuery("USER_ID=", userContext.getUID()).detail();
            List<BO> listCY = SDK.getBOAPI().query("BO_EU_PERSON_CYDH").bindId(bo.getBindId()).orderBy("ORDERNUM").asc().list();
            List<BO> totalList = SDK.getBOAPI().query("BO_EU_FUNCTION_TYPE").orderBy("ORDERNUM").asc().list();

            String sql = "SELECT * FROM VIEW_EU_DH_VIEWS WHERE LINKURL IS NOT NULL AND LINKURL <> '/' AND APPID IS NOT NULL";
            List<RowMap> totalNavData = DBSql.getMaps(sql);
            List<BO> listAll = SDK.getBOAPI().query("BO_EU_FUNCTION_LIST").orderBy("ORDERNUM").asc().list();
            String sqlHid = "select * from BO_EU_FUNCTION_HID";
            List<RowMap> listhid = DBSql.getMaps(sqlHid);
            ProcessUtil processUtil = new ProcessUtil();
            for (BO bo1 : totalList) {
                boolean result = SDK.getPermAPI().havingACPermission(userContext.getUID(), "platform.process", bo1.getId(), 0);
                if (result) {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("typeName", bo1.getString("TYPE_NAME"));
                    jsonObject.put("typeId", bo1.getString("TYPE_ID"));
                    List<JSONObject> infoList = new ArrayList<>();
                    jsonObject.put("isHidden", true);
                    //查询细项
                    List<BO> list1 = listAll.stream().filter(bo2 -> bo2.getBindId().equals(bo1.getBindId())).collect(Collectors.toList());
                    for (BO bo222 : list1) {
                        String functionid = bo222.getString("FUNCTIONID");
                        List<RowMap> resultList = totalNavData.stream().filter(rowMap -> rowMap.getString("ID").equals(functionid)).collect(Collectors.toList());
                        if (resultList == null || resultList.size() == 0) {
                            continue;
                        }
                        RowMap rowMap1111 = resultList.get(0);
                        String isdel = bo222.getString("ISDEL");
                        //所有隐藏人员
                        List<RowMap> list2 = listhid.stream().filter(rowMap -> rowMap.getString("BINDID").equals(bo222.getId())).collect(Collectors.toList());
                        if (!SDK.getPermAPI().havingACPermission(userContext.getUID(), "platform.process", bo222.getId(), 0)) {
                            continue;
                        }

//                        if (!PermAPIManager.getInstance().havingModelPermission(userContext.getUID(), rowMap1111.getString("ID"))) {
//                            continue;
//                        }
//                        if (!SDK.getPermAPI().havingNavMenuPermission(userContext.getUID(),rowMap1111.getString("ID"))) {
//                        if (!processUtil.getAc(userPermissionAssnList,deptPermissionAssnList,rolePermissionAssnList,mapRoles,rowMap1111.getString("ID"),q1Model,currentUserModel)) {
//                            continue;
//                        }
                        //是此菜单
                        JSONObject jsonObjectListInfo = new JSONObject();
                        jsonObjectListInfo.put("functionId", functionid);
                        jsonObjectListInfo.put("name", rowMap1111.getString("NAME"));
                        String icon16 = rowMap1111.getString("ICON16");
                        if (StringUtil.isEmpty(icon16)) {
                            icon16 = "&#xe870;|#ff9421";
                        }
//                        jsonObjectListInfo.put("icon16", funModel.getIcon16());
//                        jsonObjectListInfo.put("icon64", funModel.getIcon64());
//                        jsonObjectListInfo.put("icon96", funModel.getIcon96());
                        if (icon16.contains("../")) {
                            icon16 = SDK.getPortalAPI().getPortalUrl() + "/" + icon16.replace("../", "");
                        } else if (icon16.contains("./")) {
                            icon16 = SDK.getPortalAPI().getPortalUrl() + "/r/" + icon16.replace("./", "").replace("sid=", "sid=" + userContext.getSessionId());
                        } else if (icon16.contains("data:image")) {
                            icon16 = "&#xe870;|#ff9421";
                        }
                        jsonObjectListInfo.put("icon16", icon16);
                        String linkurl = rowMap1111.getString("LINKURL");
                        if (linkurl.contains("./w")){
                            jsonObjectListInfo.put("url", SDK.getPortalAPI().getPortalUrl() + "/r/" + (SDK.getRuleAPI().executeAtScript(rowMap1111.getString("LINKURL"), userContext).replace("./", "")));
                        }else{
                            if (linkurl.contains("@")){
                                jsonObjectListInfo.put("url", SDK.getRuleAPI().executeAtScript(rowMap1111.getString("LINKURL"), userContext));
                            }else{
                                jsonObjectListInfo.put("url", linkurl);
                            }
                        }
                        jsonObjectListInfo.put("appId", rowMap1111.getString("APPID"));
                        List<BO> cy = listCY.stream().filter(bo2 -> functionid.equals(bo2.getString("FUNCTIONID"))).collect(Collectors.toList());
                        if (cy != null && cy.size() > 0) {
                            jsonObjectListInfo.put("isCy", true);
                        } else {
                            jsonObjectListInfo.put("isCy", false);
                        }
                        jsonObjectListInfo.put("isDel", isdel);
                        /**
                         * 判断是否隐藏了
                         */
                        List<RowMap> list3 = list2.stream().filter(rowMap -> rowMap.getString("USER_ID").equals(userContext.getUID())).collect(Collectors.toList());
                        if (list3 != null && list3.size() > 0) {
                            jsonObjectListInfo.put("isHidden", true);
                        } else {
                            jsonObject.put("isHidden", false);
                            jsonObjectListInfo.put("isHidden", false);
                        }
                        infoList.add(jsonObjectListInfo);
                    }
                    jsonObject.put("listFunction", infoList);
                    list.add(jsonObject);
                }
            }
            responseObject.setData(list);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 通用功能隐藏、添加
     */
    @Mapping("portal.person.operafunctionlist")
    public ResponseObject hiddenFunction(UserContext userContext, String type, String functionId) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            List<BO> list = SDK.getBOAPI().query("BO_EU_FUNCTION_LIST").addQuery("FUNCTIONID=", functionId).list();
            if (list == null || list.size() == 0) {
                responseObject = ResponseObject.newErrResponse("系统获取菜单出错，请联系管理员核查！");
            } else {
                if ("hidden".equals(type)) {
                    for (BO bo1 : list) {
                        String bindid = bo1.getId();
                        BO bo11 = new BO();
                        bo11.set("USER_ID", userContext.getUID());
                        int result = SDK.getBOAPI().create("BO_EU_FUNCTION_HID", bo11, bindid, userContext.getUID());
                    }
                } else {
                    for (BO bo1 : list) {
                        String bindid = bo1.getId();
                        BO bo = SDK.getBOAPI().query("BO_EU_FUNCTION_HID").addQuery("USER_ID=", userContext.getUID()).addQuery("BINDID=", bindid).detail();
                        if (bo != null) {
                            SDK.getBOAPI().remove("BO_EU_FUNCTION_HID", bo.getId());
                        } else {
                            responseObject = ResponseObject.newErrResponse("此菜单已取消隐藏！");
                        }
                    }
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 常用功能查询
     */
    @Mapping("portal.person.getcylist")
    public ResponseObject getCyList(UserContext userContext) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            /**
             * 权限
             */

            UserModel currentUserModel = SDK.getORGAPI().getUser(userContext.getUID());
            Query1Model q1Model = new Query1Model();
            List<PermissionAssnModel> userPermissionAssnList = q1Model.getUserPermissionAssnListByUID(userContext.getUID());
            List<PermissionAssnModel> deptPermissionAssnList = q1Model.getDeptPermissionAssnListByDeptId(currentUserModel.getDepartmentId());
            List<PermissionAssnModel> rolePermissionAssnList = q1Model.getRolePermissionAssnListByRoleId(currentUserModel.getRoleId());
            List<UserMapModel> mapRoles = UserMapCache.getMapListOfUser(userContext.getUID());

            List<JSONObject> infoList = new ArrayList<>();
            ProcessUtil processUtil = new ProcessUtil();
            ResponseObject commonRe = processUtil.getCommonProcessList(userContext);
            if (commonRe.isOk()) {
                /**
                 * 获取常用数据
                 */
                Map map = commonRe.getData(Map.class);
                JSONArray commonList = (JSONArray) map.get("list");
                BO bo = SDK.getBOAPI().query("BO_EU_PERSON_MY_DH").addQuery("USER_ID=", userContext.getUID()).detail();
                if (bo == null) {
                    BO bo1 = new BO();
                    bo1.set("USER_ID", userContext.getUID());
                    ProcessInstance processInstance = SDK.getProcessAPI().createProcessInstance("obj_367fe1247ffe4e8a9bc8080a66cf89c4", userContext.getUID(), "我的菜单");
                    SDK.getBOAPI().create("BO_EU_PERSON_MY_DH", bo1, processInstance, userContext);
                    bo = SDK.getBOAPI().query("BO_EU_PERSON_MY_DH").addQuery("USER_ID=", userContext.getUID()).detail();
                }
                List<BO> list111 = SDK.getBOAPI().query("BO_EU_PERSON_CYDH").bindId(bo.getBindId()).orderBy("ORDERNUM").asc().list();
                /**
                 * 判断此人是否有此导航的权限
                 */
                String sql = "SELECT * FROM VIEW_EU_DH_VIEWS WHERE LINKURL IS NOT NULL AND LINKURL <> '/' AND APPID IS NOT NULL";
                List<RowMap> totalNavData = DBSql.getMaps(sql);

                /**
                 * 判断有没有新加的菜单
                 */
                BO boMy = SDK.getBOAPI().query("BO_EU_PERSON_MY_DH").addQuery("USER_ID=", userContext.getUID()).detail();
                if (commonList != null && commonList.size() > 0) {
                    for (int i = 0; i < commonList.size(); i++) {
                        JSONObject jsonObject = commonList.getJSONObject(i);
                        String prd = jsonObject.getString("processDefId");
                        String url = jsonObject.getString("url");
                        List<BO> list1 = list111.stream().filter(bo1 -> bo1.getString("FUNCTIONID").equals(prd)).collect(Collectors.toList());
                        if (list1 != null && list1.size() > 0) {

                        } else {
                            BO bo1 = new BO();
                            bo1.set("FUNCTIONID", prd);
                            if (list111.size() > 0) {
                                BO lastList = list111.get(list111.size() - 1);
                                bo1.set("ORDERNUM", lastList.get("ORDERNUM", Integer.class) + i);
                            } else {
                                bo1.set("ORDERNUM", i);
                            }
                            bo1.set("TYPE", "流程中心");
                            String url1[] = url.split("&sid=");
                            if (url1.length == 2) {
                                String[] url2 = url1[1].split("&");
                                if (url2.length == 1) {
                                    url = url1[0] + "&sid=" + userContext.getSessionId();
                                } else {
                                    url = url1[0] + "&sid=" + userContext.getSessionId() + "&" + url2[1];
                                }
                            }
                            bo1.set("URL", url);
                            SDK.getBOAPI().create("BO_EU_PERSON_CYDH", bo1, boMy.getBindId(), userContext.getUID());
                        }
                    }
                }
                List<BO> list = SDK.getBOAPI().query("BO_EU_PERSON_CYDH").bindId(bo.getBindId()).orderBy("ORDERNUM").asc().list();
                for (BO bo1 : list) {
                    int ordernum = bo1.get("ORDERNUM", Integer.class);
                    String functionId = bo1.getString("FUNCTIONID");
                    String type = bo1.getString("TYPE");
                    if (type.equals("通用功能")) {
                        // 判断当前用户是否可访问
//                        if (!PermAPIManager.getInstance().havingModelPermission(userContext.getUID(), functionId)) {
                        if (!processUtil.getAc(userPermissionAssnList, deptPermissionAssnList, rolePermissionAssnList, mapRoles, functionId, q1Model, currentUserModel)) {
                            continue;
                        }
                        List<RowMap> resultList = totalNavData.stream().filter(rowMap -> rowMap.getString("ID").equals(functionId)).collect(Collectors.toList());
                        if (resultList == null || resultList.size() == 0) {
                            continue;
                        }
                        RowMap rowMap1111 = resultList.get(0);

                        if (rowMap1111 != null) {
                            //是此菜单
                            JSONObject jsonObjectListInfo = new JSONObject();
                            jsonObjectListInfo.put("functionId", functionId);
                            jsonObjectListInfo.put("name", rowMap1111.getString("NAME"));
                            String icon16 = rowMap1111.getString("ICON16");
                            if (StringUtil.isEmpty(icon16)) {
                                icon16 = "&#xe870;|#ff9421";
                            }
                            if (icon16.contains("../")) {
                                icon16 = SDK.getPortalAPI().getPortalUrl() + "/" + icon16.replace("../", "");
                            } else if (icon16.contains("./")) {
                                icon16 = SDK.getPortalAPI().getPortalUrl() + "/r/" + icon16.replace("./", "").replace("sid=", "sid=" + userContext.getSessionId());
                            } else if (icon16.contains("data:image")) {
                                icon16 = "&#xe870;|#ff9421";
                            }
                            jsonObjectListInfo.put("icon16", icon16);

                            jsonObjectListInfo.put("url", SDK.getPortalAPI().getPortalUrl() + "/r/" + (SDK.getRuleAPI().executeAtScript(rowMap1111.getString("LINKURL"), userContext).replace("./", "")));
                            jsonObjectListInfo.put("appId", rowMap1111.getString("APPID"));
                            jsonObjectListInfo.put("ordernum", ordernum);
                            infoList.add(jsonObjectListInfo);
                        }
                    } else {
                        ProcessDefinition processDefinition = SDK.getRepositoryAPI().getProcessDefinition(functionId);
                        if (processDefinition != null) {
                            //是此菜单
                            JSONObject jsonObjectListInfo = new JSONObject();
                            jsonObjectListInfo.put("functionId", functionId);
                            jsonObjectListInfo.put("name", processDefinition.getProcessGroupName());
                            String icon16 = processDefinition.getIconFontCode() + "|" + processDefinition.getIconFontColor();
                            if (StringUtil.isEmpty(processDefinition.getIconFontCode())) {
                                icon16 = "&#xe870;|#ff9421";
                            }
                            if (icon16.contains("../")) {
                                icon16 = SDK.getPortalAPI().getPortalUrl() + "/" + icon16.replace("../", "");
                            } else if (icon16.contains("./")) {
                                icon16 = SDK.getPortalAPI().getPortalUrl() + "/r/" + icon16.replace("./", "").replace("sid=", "sid=" + userContext.getSessionId());
                            } else if (icon16.contains("data:image")) {
                                icon16 = "&#xe870;|#ff9421";
                            }
                            jsonObjectListInfo.put("icon16", icon16);


                            String url = SDK.getPortalAPI().getPortalUrl() + "/r/" + (SDK.getRuleAPI().executeAtScript(bo1.getString("URL"), userContext).replace("./", ""));
                            String url1[] = url.split("&sid=");
                            if (url1.length == 2) {
                                String[] url2 = url1[1].split("&");
                                if (url2.length == 1) {
                                    url = url1[0] + "&sid=" + userContext.getSessionId();
                                } else {
                                    url = url1[0] + "&sid=" + userContext.getSessionId() + "&" + url2[1];
                                }
                            }

                            jsonObjectListInfo.put("url",url );
                            jsonObjectListInfo.put("appId", processDefinition.getAppId());
                            jsonObjectListInfo.put("ordernum", ordernum);
                            infoList.add(jsonObjectListInfo);
                        }
                    }
                }
            }
            responseObject.setData(infoList);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 常用功能排序
     */
    @Mapping("portal.person.pxcylist")
    public ResponseObject pxCyList(UserContext userContext, String functionId, String newFunctionId) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            BO bo = SDK.getBOAPI().query("BO_EU_PERSON_MY_DH").addQuery("USER_ID=", userContext.getUID()).detail();
            BO bo1 = SDK.getBOAPI().query("BO_EU_PERSON_CYDH").addQuery("FUNCTIONID=", functionId).addQuery("BINDID=", bo.getBindId()).detail();
            BO bonew = SDK.getBOAPI().query("BO_EU_PERSON_CYDH").addQuery("FUNCTIONID=", newFunctionId).addQuery("BINDID=", bo.getBindId()).detail();
            int ordernum = bo1.get("ORDERNUM", Integer.class);
            int orderNewNum = bonew.get("ORDERNUM", Integer.class);
            bo1.set("ORDERNUM", orderNewNum);
            bonew.set("ORDERNUM", ordernum);
            int result = SDK.getBOAPI().update("BO_EU_PERSON_CYDH", bo1);
            int result1 = SDK.getBOAPI().update("BO_EU_PERSON_CYDH", bonew);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 常用功能新增、删除
     */
    @Mapping("portal.person.operacylist")
    public ResponseObject operaCyList(UserContext userContext, String type, String functionId) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            BO bo = SDK.getBOAPI().query("BO_EU_PERSON_MY_DH").addQuery("USER_ID=", userContext.getUID()).detail();
            List<BO> list = SDK.getBOAPI().query("BO_EU_PERSON_CYDH").bindId(bo.getBindId()).list();
            if ("delete".equals(type)) {
                BO bo1 = SDK.getBOAPI().query("BO_EU_PERSON_CYDH").addQuery("FUNCTIONID=", functionId).addQuery("BINDID=", bo.getBindId()).detail();
                if (bo1 != null) {
                    String typeN = bo1.getString("TYPE");
                    if ("流程中心".equals(typeN)) {
                        /**
                         * 取消常用
                         */
                        String commonProcessStr = SDK.getPortalAPI().getUserProfileItem("com.actionsoft.apps.workbench", userContext.getUID(), "commonProcess", "commonProcess");
                        JSONArray commonProcessArr = new JSONArray();
                        if (!UtilString.isEmpty(commonProcessStr)) {
                            commonProcessArr = JSONArray.parseArray(commonProcessStr);
                            for (int i = 0; i < commonProcessArr.size(); i++) {
                                JSONObject jsonObject = commonProcessArr.getJSONObject(i);
                                String processDefId = jsonObject.getString("processDefId");
                                if (processDefId.equals(functionId)) {
                                    commonProcessArr.remove(jsonObject);
                                }
                            }
                        }
                        SDK.getPortalAPI().setUserProfileItem("com.actionsoft.apps.workbench", userContext.getUID(), "commonProcess", "commonProcess", commonProcessArr.toJSONString());
                    }
                    SDK.getBOAPI().remove("BO_EU_PERSON_CYDH", bo1.getId());
                } else {
                    responseObject = ResponseObject.newErrResponse("此常用菜单已被删除！");
                }
            } else {
                BO bo1 = new BO();
                bo1.set("FUNCTIONID", functionId);
                bo1.set("ORDERNUM", list.size() + 1);
                bo1.set("TYPE", "通用功能");
                SDK.getBOAPI().create("BO_EU_PERSON_CYDH", bo1, bo.getBindId(), userContext.getUID());
            }
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 获取未读消息数量
     */
    @Mapping("portal.person.getunreadnum")
    public ResponseObject getUnReadNum(UserContext userContext) {
        CMSUtil cmsUtil = new CMSUtil();
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        JSONObject resultObject = new JSONObject();
        try {
            ResponseObject responseObject1 = cmsUtil.getNum(userContext);
            Map numData = responseObject1.getData(Map.class);
            int num = (int) numData.get("count");
            String url = SDK.getPortalAPI().getPortalUrl() + "/r/w?sid=" + userContext.getSessionId() + "&cmd=com.actionsoft.apps.notification_center";
            resultObject.put("num", num);
            resultObject.put("url", url);
            responseObject.setData(resultObject);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }


    /**
     * 个人日历获取周数
     */
    @Mapping(value = "portal.person.getweeks", session = false, noSessionReason = "计算周别，无须session", noSessionEvaluate = "计算周别，无需session")
    public ResponseObject getWeeks(String startDate) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        List<JSONObject> resultJson = new ArrayList<>();
        try {
            /**
             * 获取当前日期的周数
             */

            Date nDate = new Date();
            Calendar nCalendar = Calendar.getInstance();
            if (nCalendar.getFirstDayOfWeek() != Calendar.MONDAY) {
                nCalendar.setFirstDayOfWeek(Calendar.MONDAY);
            }
            nCalendar.setTime(nDate);
            int nowWeek = nCalendar.get(Calendar.WEEK_OF_YEAR);


            //开始周数
            Date sDate = simpleDateFormat.parse(startDate);
            Calendar calendar = Calendar.getInstance();
            if (calendar.getFirstDayOfWeek() != Calendar.MONDAY) {
                calendar.setFirstDayOfWeek(Calendar.MONDAY);
            }
            calendar.setTime(sDate);
            //开始周数
            int startWeek = calendar.get(Calendar.WEEK_OF_YEAR);
            //周数+6
            for (int i = 0; i < 6; i++) {
                int sendWeek = startWeek + i;
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("week", sendWeek);
                if (nowWeek == sendWeek) {
                    jsonObject.put("isselect", 1);
                } else {
                    jsonObject.put("isselect", 0);
                }
                resultJson.add(jsonObject);
            }
            responseObject.setData(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 个人日历获取存在会议和待办的日期数
     */
    @Mapping("portal.person.getdays")
    public ResponseObject getPersonDays(UserContext userContext) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            PortalGroupUtli portalGroupUtli = new PortalGroupUtli();
            Set<String> totalDate = new HashSet<>();
            JSONObject resultJson = new JSONObject();
            MeetingUtil meetingUtil = new MeetingUtil();
            List<String> meetingList = meetingUtil.searchMeetingDate(userContext.getUID());
            for (String date : meetingList) {
                totalDate.add(date);
            }
            List<BO> list = SDK.getBOAPI().query("BO_EU_PER_WDRC").addQuery("USER_ID=", userContext.getUID()).list();
            for (BO bo : list) {
                String amstarttime = bo.getString("SDATE");
                Date sDate = simpleDateFormat.parse(amstarttime);
                String pmendtime = bo.getString("EDATE");
                Date eDate = simpleDateFormat.parse(pmendtime);
                totalDate.addAll(portalGroupUtli.getDatesBetween(sDate, eDate));
            }
            resultJson.put("restDays", totalDate);
            responseObject.setData(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 个人日历获取点击日期存在的会议和备忘录
     */
    @Mapping("portal.person.getdaysinfo")
    public ResponseObject getDaysInfo(UserContext userContext, String date) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            List<JSONObject> meetingList = new ArrayList<>();
            List<JSONObject> bwlList = new ArrayList<>();
            JSONObject resultJson = new JSONObject();
            MeetingUtil meetingUtil = new MeetingUtil();
            List<RowMap> result = meetingUtil.getDateMeetingList(date, userContext.getUID());
            for (RowMap rowMap : result) {
                String title = rowMap.getString("SUBJECT");
                String booktimebegin = rowMap.getString("BOOKTIMEBEGIN");
                Date dateStart = simpleDateFormat1.parse(booktimebegin);
                String booktimeend = rowMap.getString("BOOKTIMEEND");
                Date dateEnd = simpleDateFormat1.parse(booktimeend);
                String[] begins = booktimebegin.split(" ");
                String[] ends = booktimeend.split(" ");
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("title", title);
                jsonObject.put("start", simpleDateFormat.format(dateStart));
                jsonObject.put("end", simpleDateFormat.format(dateEnd));
                meetingList.add(jsonObject);
            }
            String sql = "select * from BO_EU_PER_WDRC where USER_ID='" + userContext.getUID() + "' and EDATE>=TO_DATE('" + date + " 00:00:00','YYYY-MM-DD HH24:MI:SS') and SDATE<=TO_DATE('" + date + " 23:59:59','YYYY-MM-DD HH24:MI:SS') order by SDATE asc";
            List<RowMap> list = DBSql.getMaps(sql);
            for (RowMap bo : list) {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("title", bo.getString("TITLE"));
                jsonObject.put("remark", bo.getString("REMARK"));
                jsonObject.put("id", bo.getString("ID"));
                jsonObject.put("sdate", bo.getString("SDATE"));
                jsonObject.put("edate", bo.getString("EDATE"));
                bwlList.add(jsonObject);
            }
            resultJson.put("metting", meetingList);
            resultJson.put("bwl", bwlList);
            responseObject.setData(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }


    /**
     * 个人日历添加备忘录
     */
    @Mapping("portal.person.addinfo")
    public ResponseObject addInfo(UserContext userContext, String sDate, String eDate, String title, String remark) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            ProcessInstance processInstance = SDK.getProcessAPI().createProcessInstance("obj_675252bc1b3941d882aa3db5676bfd6e", userContext.getUID(), "增加日程");
            BO bo = new BO();
            bo.set("SDATE", sDate);
            bo.set("EDATE", eDate);
            bo.set("TITLE", title);
            bo.set("REMARK", remark);
            bo.set("USER_ID", userContext.getUID());
            SDK.getBOAPI().create("BO_EU_PER_WDRC", bo, processInstance, userContext);
            responseObject.setData(bo.getId());
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }


    /**
     * 个人日历修改备忘录
     */
    @Mapping("portal.person.xginfo")
    public ResponseObject addInfo(UserContext userContext, String id, String sDate, String eDate, String title, String remark) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            BO bo = SDK.getBOAPI().query("BO_EU_PER_WDRC").detailById(id);
            bo.set("SDATE", sDate);
            bo.set("EDATE", eDate);
            bo.set("TITLE", title);
            bo.set("REMARK", remark);
            bo.set("USER_ID", userContext.getUID());
            SDK.getBOAPI().update("BO_EU_PER_WDRC", bo);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 个人日历删除备忘录
     */
    @Mapping("portal.person.removeinfo")
    public ResponseObject addInfo(UserContext userContext, String id) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            BO bo = SDK.getBOAPI().query("BO_EU_PER_WDRC").detailById(id);
            SDK.getBOAPI().remove("BO_EU_PER_WDRC", id);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 催办
     */
    @Mapping("portal.person.cb")
    public ResponseObject cb(UserContext userContext, String userIds, String processInstId) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            String[] users = userIds.split(",");
            ProcessInstance processInstance = SDK.getProcessAPI().getInstanceById(processInstId);
            SDK.getProcessAPI().remindMail(userContext, processInstance);
            String title = processInstance.getTitle();
            String content = "【您有一条新的催办消息，请及时办理】，流程标题：" + title;
            for (String user : users) {
                //发送催办系统消息
                SDK.getNotificationAPI().sendMessage(userContext.getUID(), user, content);
                //发送催办
                UserModel userModel = SDK.getORGAPI().getUser(user);
                if (userModel != null) {
                    sendMailToUser("【任务催办提醒,来自：" + userContext.getUserName() + "】", content, userModel.getEmail(), "");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 压缩图片
     */
    @Mapping("portal.person.ystp")
    public ResponseObject ystp(UserContext userContext, String bindid) {
        ResponseObject responseObject = ResponseObject.newOkResponse("操作成功");
        try {
            PortalGroupUtli portalGroupUtli = new PortalGroupUtli();
            portalGroupUtli.ystp(userContext, bindid);
        } catch (Exception e) {
            e.printStackTrace();
            responseObject = ResponseObject.newErrResponse("操作失败！");
        } finally {
            return responseObject;
        }
    }

    /**
     * 顶部菜单特殊打开
     */
    @Mapping("portal.person.topts")
    public String topts(UserContext me, String type, String id) {
        Map<String, Object> result = new HashMap();
        result.put("sid", me.getSessionId());
        result.put("type", type);
        result.put("id", id);
        AppAPI appApi = SDK.getAppAPI();
        PortalAPI portalApi = SDK.getPortalAPI();
        boolean isSystem = SDK.getPermAPI().isSystemAdministrator(me.getUID());
        result.put("isSystem", isSystem);
        UserModel userModel = me.getUserModel();
        result.put("companyName", me.getCompanyModel().getName());
        result.put("departmentName", me.getDepartmentModel().getName());
        result.put("uid", userModel.getUID());
        result.put("uniqueId", userModel.getUniqueId());
        result.put("userName", userModel.getUserName());
        result.put("userPhoto", portalApi.getUserPhoto(me, me.getUID()));
        result.put("userPhotoTmp", PhotoProcessor.getTmpPhotoUrl(me, me.getUID()));
        result.put("sysAppId", "_bpm.platform");
        String isPromptUploadPortraitStr = appApi.getProperty("com.actionsoft.apps.skins.mportal3", "isPromptUploadPortrait");
        boolean isPromptUploadPortrait = false;
        if (!UtilString.isEmptyByTrim(isPromptUploadPortraitStr)) {
            try {
                isPromptUploadPortrait = Boolean.parseBoolean(isPromptUploadPortraitStr);
            } catch (Exception var37) {
                var37.printStackTrace();
            }

            isPromptUploadPortrait = isPromptUploadPortrait && "../commons/img/photo.png".equals(result.get("userPhoto") == null ? "" : result.get("userPhoto").toString());
        }

        result.put("isPromptUploadPortrait", isPromptUploadPortrait);
        String uploadPortraitPop = appApi.getProperty("com.actionsoft.apps.skins.mportal3", "uploadPortraitPop");
        result.put("uploadPortraitPop", uploadPortraitPop);
        PublicPortalWeb publicPortalWeb = new PublicPortalWeb(me);
        net.sf.json.JSONObject loginCheckSecurity = publicPortalWeb.loginCheckSecurity();
        result.putAll(loginCheckSecurity);
        String requiredUserInfo = portalApi.getRequiredUserInfo(me);
        String[] requiredUserInfoArray = requiredUserInfo.split("[|]");
        boolean requiredEmail = false;
        boolean requiredOfficeTel = false;
        boolean requiredMobile = false;
        String[] var20 = requiredUserInfoArray;
        int notificationMsgLoadFrequency = requiredUserInfoArray.length;

        for (int var18 = 0; var18 < notificationMsgLoadFrequency; ++var18) {
            String reqUserInfo = var20[var18];
            if ("email".equals(reqUserInfo.toLowerCase())) {
                requiredEmail = true;
            } else if ("officetel".equals(reqUserInfo.toLowerCase())) {
                requiredOfficeTel = true;
            } else if ("mobile".equals(reqUserInfo.toLowerCase())) {
                requiredMobile = true;
            }
        }

        result.put("requiredEmail", requiredEmail);
        result.put("requiredOfficeTel", requiredOfficeTel);
        result.put("requiredMobile", requiredMobile);
        boolean isStartNotification = false;
        AppContext appCtx = appApi.getAppContext("com.actionsoft.apps.notification");
        if (appCtx != null) {
            isStartNotification = "ACTIVE".equals(appCtx.getRuntimeState());
        }

        result.put("isStartNotification", isStartNotification);
        notificationMsgLoadFrequency = Integer.parseInt(appApi.getProperty("com.actionsoft.apps.skins.mportal3", "notificationMsgLoadFrequency"));
        result.put("notificationMsgLoadFrequency", notificationMsgLoadFrequency);
        String notificationShowType = appApi.getProperty("com.actionsoft.apps.skins.mportal3", "notificationShowType");
        String notifyCollectShowNumStr = appApi.getProperty("com.actionsoft.apps.skins.mportal3", "notifyCollectShowNum");
        int notifyCollectShowNum = 0;
        if (!UtilString.isEmpty(notifyCollectShowNumStr)) {
            notifyCollectShowNum = Integer.parseInt(notifyCollectShowNumStr);
        }

        result.put("notificationShowType", notificationShowType);
        result.put("notifyCollectShowNum", notifyCollectShowNum);
        String portalId = "f2a3b3da-32b0-46a8-8461-3a3c9569cb7d";
        if (UtilString.isEmpty(portalId)) {
            return AlertWindow.getAuthorityMessagePage("您访问的模板不存在或者未授权", (String) null);
        } else {
            net.sf.json.JSONObject json = new net.sf.json.JSONObject();
            result.put("config", net.sf.json.JSONObject.fromObject(json));
            result.put("portalName", json.opt("portalName"));
            result.put("favicon", json.opt("favicon"));
            net.sf.json.JSONArray commonNavArr = new net.sf.json.JSONArray();
            result.put("commonNavArr", commonNavArr);
            result.put("commonSubNum", 0);
            net.sf.json.JSONArray quitEntryList = new net.sf.json.JSONArray();
            result.put("quitEntryList", quitEntryList);
            net.sf.json.JSONObject mainNav = new net.sf.json.JSONObject();
            net.sf.json.JSONArray mainNavArr = new net.sf.json.JSONArray();
            result.put("mainNavArr", mainNavArr);
            result.put("headerCode", json.opt("headerCode"));
            result.put("mainNavCode", mainNav.opt("mainNavCode"));
            result.put("bottomCode", json.opt("bottomCode"));
            boolean isStartRong = false;
            AppContext RongCtx = appApi.getAppContext("com.actionsoft.apps.rongim");
            if (RongCtx != null) {
                isStartRong = "ACTIVE".equals(RongCtx.getRuntimeState());
            }

            result.put("isStartRong", isStartRong);
            boolean isStartMobilePortal = false;
            AppContext mpCtx = appApi.getAppContext("com.actionsoft.apps.byod.helper");
            if (mpCtx != null) {
                isStartMobilePortal = "ACTIVE".equals(mpCtx.getRuntimeState());
            }

            result.put("isStartMobilePortal", isStartMobilePortal);
            return HtmlPageTemplate.merge("com.awspaas.user.apps.forehope.portal", "mportal3.html", result);
        }
    }

    /**
     * 移动端公司门户
     *
     * @param userContext
     * @param bindid
     * @return
     */
    @Mapping(value = "portal.mobilegr")
    public String getMobilegr(UserContext userContext, String bindid) {
        Map<String, Object> macroLibraries = new LinkedHashMap<String, Object>();
        String sid = userContext.getSessionId();
        macroLibraries.put("sid", sid);
        return HtmlPageTemplate.merge("com.awspaas.user.apps.forehope.portal", "mobilegr.html", macroLibraries);
    }


    /**
     * 移动端公司门户
     *
     * @param userContext
     * @return
     */
    @Mapping(value = "portal.changeportaltype")
    public String changePortal(UserContext userContext) {
        ResponseObject r = ResponseObject.newOkResponse("门户切换成功");
        String portaltype = userContext.getExtParam("portaltype") == null ? "" : userContext.getExtParam("portaltype").toString();
        if ("new".equals(portaltype)) {
            userContext.setExtParam("portaltype", "old");
        } else {
            userContext.setExtParam("portaltype", "new");
        }
        return r.toString();
    }


    /**
     * 移动端公司门户
     *
     * @param userContext
     * @return
     */
    @Mapping(value = "portal.shenpi")
    public String shenpi(UserContext userContext) {
        ResponseObject r = ResponseObject.newOkResponse();
        userContext.setExtParam("issp", "1");
        return r.toString();
    }

    /**
     * 获取是否有待办
     *
     * @param userContext
     * @return
     */
    @Mapping(value = "portal.getusersession")
    public String getusersession(UserContext userContext) {
        ResponseObject r = ResponseObject.newOkResponse();
        String issp = userContext.getExtParam("issp") == null ? "0" : userContext.getExtParam("issp").toString();
        r.setData(issp);
        userContext.setExtParam("issp", "0");
        return r.toString();
    }

    /**
     * 修改密码
     *
     * @param userContext
     * @return
     */
    @Mapping(value = "portal.changepassword")
    public String changePassWord(UserContext userContext,String oldPassWord,String newPassWord) {
        ResponseObject r = ResponseObject.newOkResponse();
        try{
            boolean result = SDK.getORGAPI().changeUserPWD(userContext.getUID(),oldPassWord,newPassWord);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseObject.newErrResponse(e.getMessage());
        }
        return r.toString();
    }




}
